import Mock from 'mockjs'

// 查询课程列表
export const getCourseListPage = async (params: CourseList): Promise<ListCourseListRes> => {
  const res = await Mock.mock({
    'list|10': [
      {
        'id|+1': 1,
        courseName: '@cname',
        courseCoverUrl: "@image('200x200', '#50B347', '#FFF', 'Mock.js')",
        courseDetail: '@cword(3, 5)',
        sortNo: 99,
        'courseType|1': [1, 2],
        'courseStatus|1': [1, 2],
        'isRecommend|1': [0, 1],
        validDays: 365,
        createTime: 1691727146870
      }
    ],
    total: 100,
    pageNo: 1,
    pageSize: 10
  })
  return res
}

// 查询课程详情
export const getCourse = async (id: number) => {
  const res = await Mock.mock({
    'id|+1': 1,
    courseName: '@cname',
    courseCoverUrl: "@image('200x200', '#50B347', '#FFF', 'Mock.js')",
    courseDetail: '@cword(3, 5)',
    'courseType|1': [1, 2],
    'courseStatus|1': [1, 2],
    'isRecommend|1': [0, 1],
    sortNo: 99,
    validDays: 365,
    createTime: 1691727146870
  })
  return res
}

// 修改课程
export const updateCourse = async (data: CourseList): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

// 删除课程
export const deleteCourse = async (id: number): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

// 创建课程
export const createCourse = async (params: CourseList): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

// 根据条目名称模糊查询
export const dimselectCourseItem = async (keyword: string): Promise<CourseItem> => {
  return Mock.mock({
    'data|10': [
      {
        'id|+1': 1,
        itemName: '@cname',
        itemDesc: '@cword(3, 5)',
        'courseType|1': [1, 2, 3, 4],
        'itemStatus|1': [1, 2],
        'isFree|1': [0, 1],
        createTime: 1691727146870
      }
    ]
  })
}

// 根据课程id，获取课程的目录以及条目的树形结构
export const getCourseCatalogTree = async (id: string): Promise<CourseCatalogTree> => {
  return await Mock.mock({
    'data|2': [
      {
        id: '@integer(1, 1000)',
        label: '@cword(3, 5)',
        'children|4': [
          {
            id: '@integer(1, 1000)',
            label: '@cword(3, 5)'
          }
        ]
      }
    ]
  })
}
